package com.internetCafes.spms.web.customer.service.impl.customer;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.internetCafes.spms.web.customer.entity.customer.CustomerQualiImage;
import com.internetCafes.spms.web.customer.mapper.customer.CustomerQualiImageMapper;
import com.internetCafes.spms.web.customer.service.customer.ICustomerQualiImageService;
import com.sms.common.util.hutool.core.collection.CollectionUtil;
import com.sms.common.util.hutool.core.util.StrUtil;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 客户资质证明图片表 服务实现类
 * </p>
 *
 * @author Zj
 * @since 2021-10-20
 */
@Service
public class CustomerQualiImageServiceImpl extends ServiceImpl<CustomerQualiImageMapper, CustomerQualiImage> implements ICustomerQualiImageService {

    @Override
    public boolean removeByCustomerIdList(List<Long> customerIdList) {
        return remove(new LambdaQueryWrapper<CustomerQualiImage>().in(CustomerQualiImage::getCustomerId, customerIdList));
    }

    @Override
    public boolean config(Long customerId, List<String> qualiImageList) {
        remove(new LambdaQueryWrapper<CustomerQualiImage>()
                .eq(CustomerQualiImage::getCustomerId, customerId));
        if (CollectionUtil.isNotEmpty(qualiImageList)) {
            List<CustomerQualiImage> qualiImageBatchDo = qualiImageList
                    .stream()
                    .filter(StrUtil::isNotBlank)
                    .map(qualiImageUrl -> {
                        CustomerQualiImage qualiImage = new CustomerQualiImage();
                        qualiImage.setCustomerId(customerId)
                                .setImageUrl(qualiImageUrl);
                        return qualiImage;
                    }).collect(Collectors.toList());
            saveBatch(qualiImageBatchDo);
        }
        return true;
    }
}
